package com.example.cloud.controller.system;

import com.example.cloud.controller.common.BaseController;
import com.example.cloud.model.dto.Result;
import com.example.cloud.model.system.Announce;
import com.example.cloud.service.system.AnnounceService;
import com.example.cloud.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wangtao on 2018/1/26.
 */
@RestController
@RequestMapping("/announce")
public class AnnounceController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(AnnounceController.class);

    @Autowired
    private AnnounceService announceService;

    @GetMapping("/find")
    public Result find(){
        Map<String, Object> params = new HashMap<>();
        Announce announce = announceService.findOne();
        if(announce == null){
            announce = new Announce();
            announce.setTitle("");
            announce.setContent("");
        }
        params.put("content", announce.getContent().split(";"));
        return ResultUtil.success(announce, params);
    }

    @PostMapping("/saveOrUpdate")
    public void saveOrUpdate(@RequestBody Announce record) {
        announceService.doSave(record);
    }

}
